<template>
	<div v-if="!isLogin">
		<h1>
			此页面需要登录
		</h1>
		<router-link to="/login">去登录</router-link>
	</div>
	<div v-else>
		<h1>你好，张三</h1>
		<button @click="logoutHandler">退出登录</button>
	</div>
</template>

<script lang="ts">
import { defineComponent } from 'vue'
import { mapState, mapActions } from "vuex";

export default defineComponent({
	computed: {
		...mapState(['isLogin'])
	},
	methods: {
		...mapActions(['logout']),
		async logoutHandler() {
			await this.logout()
			this.$router.replace('/')
		}
	}
})
</script>

<style scoped>

</style>
